import React from 'react';
import LayoutContentWrapper from '@iso/components/utility/layoutWrapper';
import LayoutContent from '@iso/components/utility/layoutContent';
import axios from "../../../../http";
import Card from "@iso/containers/UIElements/Card/Card.styles";
import {Fieldset, Form, Label} from "@iso/containers/FirestoreCRUD/Article/Article.styles";
import Qs from 'qs'
import PageHeader from '@iso/components/utility/pageHeader';
import {withRouter} from "react-router";
import cookie from "react-cookies";
import {showErrorMessage} from "@iso/containers/Feedback/Message/MessageUtils";

 class NoticeView extends React.Component {


    constructor(props) {
        super(props);
        this.state={data:[],title:'',content:'', categorySelectedKeys:[],autoSave:true};
    }

    getShareCode=()=>{
        let href=window.location.href;
        let lastIndex=href.lastIndexOf('/')
        let shareCode=href.substring(lastIndex+1,href.length)
        return shareCode;
   }

    loadData=() =>{
         axios.post('api/core/notice/publish/getOne', Qs.stringify({
             publishedCode:this.props.match.params.publishedCode
        }),{headers: {'Content-Type': 'application/x-www-form-urlencoded'}})
            .then((response)=>{
                let  data=response.data;
                if(data.status==1){
                    this.setState(data.data)
                }
            })
            .catch(function (error) {
                showErrorMessage(error);
            });

    }


   componentDidMount() {

           this.loadData();

   }


    render() {
    return (
      <LayoutContentWrapper >
          <PageHeader>
              {this.state.title}
          </PageHeader>
        <LayoutContent>


            <Card
                title=''
                style={{ width: '100%' }}
            >

                <Form >

                    <Fieldset>
                        <Label>内容:</Label>
                        <div dangerouslySetInnerHTML={{__html:this.state.content}}></div>

                    </Fieldset>

                </Form>


            </Card>

        </LayoutContent>
      </LayoutContentWrapper>
    );
  }
}
// this wrapper is for fixing bug that we can not get this.props.location
export default withRouter(NoticeView)
